﻿Imports System.Collections.Specialized
Imports System.ComponentModel.Composition
Imports System.ComponentModel.Composition.Hosting
Imports Send2Twitter

<ExportCompent(GetType(IInfoProvider), "Winamp", "4f3a51e9-8a2f-421a-a086-0ffba6322cd2", "1.0.0.1")>
Public Class WinampInfoGen
    Inherits InfoProviderBase

    Private WinampWatcher As WinampInfo = Nothing


    Public Overrides Function GetAvailability() As Boolean
        WinampWatcher.RefreshState()
        If WinampWatcher.GetPlayStatus <> WinampInfo.WinampState.Playing Then
            Return False
        Else
            Return True
        End If
    End Function

    Public Overrides Function GetInfo() As Dictionary(Of String, String)
        Dim Infos As New Dictionary(Of String, String)
        WinampWatcher.RefreshState()
        Dim tag = WinampWatcher.CurrentFileTag
        On Error Resume Next
        Infos.Add("filepath", WinampWatcher.GetFilePath)
        Infos.Add("bitrate", WinampWatcher.GetBitRate)
        Infos.Add("channels", WinampWatcher.GetChannels)
        Infos.Add("filetype", WinampWatcher.GetFileType)
        Infos.Add("samplerate", WinampWatcher.GetSampleRate)
        Infos.Add("trackposition", WinampWatcher.GetTrackPosition.ToString)
        Infos.Add("tracktime", WinampWatcher.GetTrackTime.ToString)
        Infos.Add("percent", WinampWatcher.ProgressPercents)
        If tag Is Nothing Then Return Infos
        Infos.Add("album", tag.GetAlbum)
        Infos.Add("albumartist", tag.GetAlbumArtist)
        Infos.Add("artist", tag.GetArtist)
        Infos.Add("bpm", tag.GetBPM)
        Infos.Add("comment", tag.GetComment)
        Infos.Add("composers", tag.GetComposers)
        Infos.Add("conductor", tag.GetConductor)
        Infos.Add("copyright", tag.GetCopyright)
        Infos.Add("disc", tag.GetDisc)
        Infos.Add("disccount", tag.GetDiscCount)
        Infos.Add("genres", tag.GetGenres)
        Infos.Add("lyric", tag.GetLyric)
        Infos.Add("title", tag.GetTitle)
        Infos.Add("track", tag.GetTrack)
        Infos.Add("trackcount", tag.GetTrackCount)
        Infos.Add("year", tag.GetYear)
        On Error GoTo 0
        tag.Dispose()
        Return Infos
    End Function

    Public Overrides Sub ShutDown()
        WinampWatcher = Nothing
    End Sub

    Public Overrides Sub StartUp()
        WinampWatcher = New WinampInfo()
    End Sub
End Class
